<?php
include("include/config.inc.php");

$pageName = 'finalProcess';

if($_SESSION['s_userType'] == 'User')
{
   $authorization = "NoAccess";
   foreach($selUsermenuArr as $value)
   {
      if(in_array($pageName, $value))
      {
        $authorization ="Access";
        break;
      }
      else 
      {
        $authorization = "NoAccess";    
      }
   }
   if($authorization == "NoAccess")
   {
     header("location:index.php");
   }
}

if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{	
  $i = 0;
  $finalprocessId   	= isset($_REQUEST['finalprocessId']) ? $_REQUEST['finalprocessId'] : 0;
  $finalprocessName 		= "";
  $isEdit 	= 0;
  $viewArr  = array();
    
  if(isset($_POST['insertBtn']))
  {
    if(isset($_POST['updatefinalprocessId']) && $_POST['updatefinalprocessId'] > 0)
    {
      $updateQuery = "UPDATE finalprocess
             								  SET finalprocessName = '".$_POST['finalprocessName']."'
	            								WHERE finalprocessId   = ".$_POST['updatefinalprocessId'];
      $updateQueryResult = mysql_query($updateQuery);
      if(!$updateQueryResult)
      die("Update Query Not Inserted : ".mysql_error());
      else
      header("Location:finalprocess.php");  
    }       
    else
    {
      $insertfp = "INSERT INTO finalprocess (finalprocessName)
                    VALUE('".$_POST['finalprocessName']."')";
      $insertfpResult = mysql_query($insertfp);
      if(!$insertfpResult)
      die("Insert Query Not Inserted : ".mysql_error());
      else
      {
        header("Location:finalprocess.php");
      }
    }
  }
  $msg              = "Record Not Found";
  $finalprocessDataArray = array();
  $editfinalprocessId   = 0;
  $editfinalprocessName = "";
  $i = 0;

  $selectfinalprocess = "SELECT finalprocessId,finalprocessName
                   FROM finalprocess
                   ORDER BY finalprocessName";
  $selectfinalprocessResult = mysql_query($selectfinalprocess);
  while($finalprocessdRow = mysql_fetch_array($selectfinalprocessResult))
  {
	  $finalprocessDataArray[$i]['finalprocessId']     = $finalprocessdRow['finalprocessId'];
	  $finalprocessDataArray[$i]['finalprocessName']   = $finalprocessdRow['finalprocessName'];
	  if($finalprocessdRow['finalprocessId']== $finalprocessId)
	{
	  $editfinalprocessId   = $finalprocessdRow['finalprocessId'];
		$editfinalprocessName = $finalprocessdRow['finalprocessName'];
	}
	  $i++;
  }
}
include("./bottom.php");
$smarty->assign("finalprocessDataArray",$finalprocessDataArray);
$smarty->assign("finalprocessId",$finalprocessId);
$smarty->assign("finalprocessName",$finalprocessName);
$smarty->assign("i",$i);
$smarty->assign("isEdit",$isEdit);
$smarty->assign("msg",$msg);
$smarty->assign("editfinalprocessId",$editfinalprocessId);
$smarty->assign("editfinalprocessName",$editfinalprocessName);
$smarty->display('finalprocess.tpl');

?>